function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {  
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function ToggleDiv(node, id) {
	sibling = document.getElementById(id);
	if (sibling.style.display == 'none') {
		if (node.childNodes.length > 0) {
			if (node.childNodes[0].tagName == "IMG") {
				node.childNodes[0].src = "http://bbsfile.ifeng.com/bbsfile/images/channel/jian.gif";
			}
		}
		sibling.style.display = '';
	} else {
		if (node.childNodes.length > 0) {
			if (node.childNodes[0].tagName == "IMG") {
				node.childNodes[0].src = "http://bbsfile.ifeng.com/bbsfile/images/channel/add.gif";
			}
		}
		sibling.style.display = 'none';
	}
}

var nn=1,tt;
addLoadEvent(troll);

function troll() {
	if(nn>5) nn=1
	//setTimeout('selectLayer('+nn+')',20);
	//setTimeout('setFocus('+nn+')',20);
	nn++;
	//tt=setTimeout('change_img()',2000);
}



function in_array(needle, haystack) {
	if(typeof needle == 'string' || typeof needle == 'number') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
					return true;
			}
		}
	}
	return false;
}

function setTab(t, cls, fid) {
	var vtab = ['tab1', 'tab2', 'tab3'];
	var stab = ['tab4', 'tab5'];

	if(in_array(t, vtab)) {
		var tab = vtab;
		var prefix = 'vtab';
	} else if(in_array(t, stab)) {
		var tab = stab;
		var prefix = 'stab';	
	} else {
		return false;	
	}

	for(var i=0; i<tab.length; i++) {
		if(t == tab[i]) {
			$(tab[i]+'_tag').className = cls;
			$(tab[i]).style.display = '';
			$(prefix+'_link').innerHTML = '<a target="_blank" href="http://bbs.ifeng.com/forumdisplay.php?fid='+fid+'">更多</a>'; 
		} else {
			$(tab[i]+'_tag').className = '';
			$(tab[i]).style.display = 'none';
		}
	}
}


var Speed = 10; //速度(毫秒)
var Space = 15; //每次移动(px)
var PageWidth = 190; //翻页宽度
var fill = 0; //整体移位
var MoveLock = false;
var MoveTimeObj;
var Comp = 0;
var AutoPlayObj=null;
var ISL_Pages = Math.floor(GetObj("List1").scrollWidth / PageWidth);
var ISL_Page = 1;
var GotoLock = false;
GetObj("List2").innerHTML = GetObj("List1").innerHTML;
GetObj('ISL_Cont').scrollLeft = fill>=0?fill:GetObj('List1').scrollWidth - Math.abs(fill);
GetObj("ISL_Cont").onmouseover = function(){clearInterval(AutoPlayObj);}
GetObj("ISL_Cont").onmouseout = function(){AutoPlay();}
AutoPlay();
//ISL_PageList();//点列表
function GetObj(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}}
function AutoPlay(){ //自动滚动
	clearInterval(AutoPlayObj);
	AutoPlayObj = setInterval('ISL_GoDown();ISL_StopDown();',9999999999999); //间隔时间
}
/*function ISL_PageList(){
	var i,temp="";
	for(i = 1;i<=ISL_Pages;i++){
		temp += "<img src='http://i2.sinaimg.cn/cj/deco/2008/0226/http://bbsfile.ifeng.com/bbsfile/images/channel/fina_mj_006.gif' class='" + (ISL_Page==i?"dotON":"dotOFF") + "' onclick='ISL_GotoPage(" + i + ")' alt='" + i + "页' />";
	};
	GetObj('dotList').innerHTML = temp;
}*/
function ISL_GotoPage(num){
	if(MoveLock)return;
	MoveLock = true;
	GotoLock = true;
	Comp = (num - 1) * PageWidth - GetObj('ISL_Cont').scrollLeft;
	ISL_Page = num;
	//ISL_PageList();
	clearInterval(AutoPlayObj);
	CompScr();
	AutoPlay();
}
function ISL_GoUp(){ //上翻开始
	if(MoveLock) return;
	clearInterval(AutoPlayObj);
	MoveLock = true;
	MoveTimeObj = setInterval('ISL_ScrUp();',Speed);
}
function ISL_StopUp(){ //上翻停止
	if(GotoLock) return;
	clearInterval(MoveTimeObj);
	if((GetObj('ISL_Cont').scrollLeft - fill) % PageWidth != 0){
		Comp = fill - (GetObj('ISL_Cont').scrollLeft % PageWidth);
		CompScr();
	}else{
		MoveLock = false;
	}
	AutoPlay();
}
function ISL_ScrUp(){ //上翻动作
	if(GetObj('ISL_Cont').scrollLeft <= 0){GetObj('ISL_Cont').scrollLeft = GetObj('ISL_Cont').scrollLeft + GetObj('List1').offsetWidth}
	GetObj('ISL_Cont').scrollLeft -= Space ;
	/*var tempPage = Math.round((GetObj('ISL_Cont').scrollLeft - fill) / PageWidth) + 1;
	if(tempPage != ISL_Page){
		ISL_Page = tempPage;
		if(ISL_Page>ISL_Pages){ISL_Page = 1};
		ISL_PageList();
	}*/
}


function ISL_GoDown(){ //下翻
	clearInterval(MoveTimeObj);
	if(MoveLock) return;
	clearInterval(AutoPlayObj);
	MoveLock = true;
	ISL_ScrDown();
	MoveTimeObj = setInterval('ISL_ScrDown()',Speed);
}
function ISL_StopDown(){ //下翻停止
	if(GotoLock) return;
	clearInterval(MoveTimeObj);
	if(GetObj('ISL_Cont').scrollLeft % PageWidth - (fill>=0?fill:fill+1) != 0 ){
		Comp = PageWidth - GetObj('ISL_Cont').scrollLeft % PageWidth + fill;
		CompScr();
	}else{
		MoveLock = false;
	}
	AutoPlay();
}
function ISL_ScrDown(){ //下翻动作
	if(GetObj('ISL_Cont').scrollLeft >= GetObj('List1').scrollWidth){GetObj('ISL_Cont').scrollLeft = GetObj('ISL_Cont').scrollLeft - GetObj('List1').scrollWidth;}
	GetObj('ISL_Cont').scrollLeft += Space;
	/*var tempPage = Math.round((GetObj('ISL_Cont').scrollLeft - fill) / PageWidth) + 1;
	if(tempPage != ISL_Page){
		ISL_Page = tempPage;
		if(ISL_Page>ISL_Pages){ISL_Page = 1};
		ISL_PageList();
	}*/
}
 
function CompScr(){
	if(Comp == 0){
		ISL_Page = Math.round((GetObj('ISL_Cont').scrollLeft - fill) / PageWidth) + 1;
		if(ISL_Page>ISL_Pages){ISL_Page = 1};
		//ISL_PageList();
		MoveLock = false;
		GotoLock = false;
		return;
	}
	
	var num;
	var TempSpeed = Speed,TempSpace = Space;
	if(Math.abs(Comp)<PageWidth/5){
		TempSpace =  Math.round(Math.abs(Comp/5));
		if(TempSpace<1){TempSpace=1};
	}
	
	if(Comp < 0){ //上翻
		if(Comp < -TempSpace){
			Comp += TempSpace;
			num = TempSpace;
		}else{
			num = -Comp;
			Comp = 0;
		}
		GetObj('ISL_Cont').scrollLeft -= num;
		setTimeout('CompScr()',TempSpeed);
	}else{ //下翻
		if(Comp > TempSpace){
			Comp -= TempSpace;
			num = TempSpace;
		}else{
			num = Comp;
			Comp = 0;
		}
		GetObj('ISL_Cont').scrollLeft += num;
		setTimeout('CompScr()',TempSpeed);
	}
}
